package org.eoti.ai.genetic.ga;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * The MIT License
 * <p/>
 * Copyright (c) 2009 Malachi de AElfweald (malachid@gmail.com)
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * GENOTYPE: Complete set of Chromosomes
 *
 * The Human genotype has 46 chromosomes
 * The first 44 are in pairs. IE: 1 & 2 are very similar
 * The 45th is an X chromosome
 * The 46th looks like an X for women, but a Y for men
 *
 * Interesting note from Wikipedia:
 * Genotype describes the genetic constitution of an individual, that is the specific allelic makeup of
 * an individual, usually with reference to a specific character under consideration [1]. For instance,
 * there are three possible genotypes for the human albino gene, and it has two allelic forms, dominant
 * A and recessive a. Thus the three possible genotypes are AA (homozygous dominant), Aa (heterozygous),
 * and aa (homozygous recessive).
 * http://en.wikipedia.org/wiki/Genotype
 *
 * The genetic identity of an individual that does not show as outward characteristics.
 * http://www.genome.gov/glossary.cfm?key=genotype
 */
public class Genotype<GENE>
implements Iterable<String>
{
	protected ConcurrentHashMap<String, Chromosome<GENE>> chromosomes;

	public Genotype()
	{
		chromosomes = new ConcurrentHashMap<String, Chromosome<GENE>>();
	}

	public Chromosome<GENE> get(String name)
	{
		return chromosomes.get(name);
	}

	public void add(Chromosome<GENE> chromosome)
	{
		chromosomes.put(chromosome.getName(), chromosome);
	}

	public Iterator<String> iterator()
	{
		return chromosomes.keySet().iterator();
	}

	public Map<Locus, GENE> getLoci(Locus ... loci)
	{
		HashMap<Locus,GENE> map = new HashMap<Locus,GENE>();
		for(Locus locus : loci)
			map.put( locus, get(locus.getChromosomeName()).get(locus.getGenePosition() ));

		return map;
	}
}
